// classList.js
var app = getApp();
var utils=require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0 ,
    codeTxt: "",
    codeTxt2: "",
    comingList:[],
    dataList:[],
    curPage:1,
    pageCount:10,
    pageSize: 10,
    rowCount: 0,
    hasMoreData: true
  },
  /**
   * tab切换
   */
  remarkTap: function (e) {
    //console.log(e.currentTarget.dataset.id);
    this.setData({
      currentTab: e.currentTarget.dataset.id
    });
  },
  /**
   * 点名
   */
  callBtn: function(e){
    var data = this.data.comingList[e.target.dataset.index];
    console.log("点名callBtn----------------",data) 
    var id = data.id;
    var classSonId = data.classSonId;
    var teamId = data.teamId;
    var why = data.why;
    var rowId = data.id;
    wx.navigateTo({
      url: '/pages/classCall/classCall?id='+id+"&classSonId="+classSonId+"&teamId="+teamId+"&rowId="+rowId+"&why="+why,
    });
  },
  /**
   * 出勤
   */
  attendBtn: function(e){
    var attendId = e.currentTarget.id;
    console.log("出勤跳转rowId为",e);
    wx.navigateTo({
      url: "/pages/classAttend/classAttend?id="+attendId
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var curPage = that.data.curPage;
    wx.request({
      url: app.globalData.http + "toDayRowClass.do",
      header: {
          'content-type': 'application/json'
      },
     data:{
       busId: parseInt(wx.getStorageSync("busId")),
       employeesId: parseInt(wx.getStorageSync("employeesId")),
       schoolId: parseInt(wx.getStorageSync("schoolId"))
     },
      success: function(res){
        console.log("即将上课----------",res.data);
        var code = res.data.code;
        if(code == 100){
            var list = res.data.data;
            var length = res.data.data.length;
            for(var i = 0; i < length; i++){
              list[i].startDate =utils.formatTime( new Date(list[i].startDate));
              console.log(list[i].startDate);
            }
            that.setData({
              comingList: res.data.data
            })
        }
        if(code == 200){
          that.setData({
            codeTxt: "暂时没有数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt: "哇哦~接口异常了"
          })
        }
      }
    });
    wx.request({
      url: app.globalData.http + "selectTeacherPastRowClass.do",
      header: {
          'content-type': 'application/json'
      },
      data: {
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("上课记录---------",res.data);
        var code = res.data.code;
        if(code == 100){
            var list = res.data.data.subList;
            var length = list.length;
            for(var i = 0; i < length; i++){
              list[i].startDate =utils.formatTime( new Date(list[i].startDate));
              console.log(list[i].startDate);
            }
            that.setData({
              dataList: list,
              curPage: curPage+1,
              pageCount: res.data.data.pageCount,
              pageSize: res.data.data.pageSize,
              rowCount: res.data.data.rowCount
            })
        }
        if(code == 200){
          that.setData({
            codeTxt2: "暂时没有数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt2: "哇哦~接口异常了"
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if(that.data.currentTab == 1){
      var hasMoreData = that.data.hasMoreData;
      var url = app.globalData.http + "selectTeacherPastRowClass.do";
      utils.loadMore(that,hasMoreData,url) 
    } 
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})